<?php
/**
 * User: lsx
 * Date: 2017/5/4
 * Time: 11:38
 * Progress:0%
 */

namespace logic\admin\index;


use model\Admin;
use think\Config;

class LPub
{
    public function login_submit($param){
        $model=new Admin();
        if(!captcha_check($param['captcha'])){
            return array(
                'success'=>false,
                'message'=>'验证码错误'
            );
        };
        if($param['nick'] == null or $param['password']==null){
            return array(
                'success'=>false,
                'message'=>'用户名或密码不能为空'
            );
        }
        $user=$model->where(['nick'=>$param['nick']])->find();
        if($user){
            if($user->flag_lock == 1){
                return array(
                    'success'=>false,
                    'message'=>'该账户已锁定，不能使用'
                );
            }
            if($user['password']==md5($param['password'])){
                $cookie_name = Config::get('const.cookie_name_admin');
                cookie($cookie_name,$user['id']);
                return array(
                    'success'=>true,
                    'message'=>'登录成功'
                );
            }else{
                return array(
                    'success'=>false,
                    'message'=>'密码错误'
                );
            }
        }else{
            return array(
                'success'=>false,
                'message'=>'用户名错误'
            );
        }
    }

}